import unittest
import os


class BaseTestCase(unittest.TestCase):
    def setUp(self):
        """子类通过重写此方法来执行特定初始化"""
        pass

    def tearDown(self):
        """子类通过重写此方法来执行特定清理"""
        pass

    def assertScoreRange(self, score, min_value=0.0, max_value=1.0, msg=None):
        """断言分数在指定范围内"""
        self.assertGreaterEqual(score, min_value, msg or f"Score {score} is less than {min_value}")
        self.assertLessEqual(score, max_value, msg or f"Score {score} is greater than {max_value}")

    def assertFileExists(self, file_path, msg=None):
        """断言文件存在"""
        self.assertTrue(os.path.exists(file_path), msg or f"File {file_path} does not exist")

    def cleanFile(self, file_path):
        """删除文件，避免污染测试环境"""
        if os.path.exists(file_path):
            try:
                os.remove(file_path)
            except PermissionError:
                pass
